|
Cytosim
PI
Cytoskeleton Simulator
|
Periodic boundary conditions are supported using a function-pointer. If keyword NO_PERIODIC_SUPPORT is defined however, inlined functions are used instead, which might be faster, but Periodic boundary are then not supported. Grid<int ORD, typename CELL, typename INDEX> creates a regular lattice over a rectangular region of space of dimensionality ORD. The grid is initialized by setDimensions() and createCells() allocates a one-dimensional array of CELL, with one value for each lattice point of the grid.
Functions are provided to convert from the real space coordinates (of type real) into an index (of type INDEX) usable to access the one-dimensional array of CELL. The cells are ordered successively, the first dimension (X) varying the fastest i.e. cell[ii+1] will in most cases be located on the right of cell[ii], although if cell[ii] is on the right edge, then cell[ii+1] is on the symmetric edge.
Cells can be accessed in three ways:
Valid indices are [0...nbCells()-1], where nbCells() is calculated by setDimensions(). If a position lies outside the rectangular region where the grid is defined, index(real[]) returns the index of the closest voxel.
Functions to convert between the three types are provided:
The grid is initialized by setDimensions(inf, sup, nbCells), which calculates:
The coordinates of a cell at position pos[] are:
and its index is
For a 4x4 2D grid, the index are like this:
The class also provides information on which cells surround each cell:
After calling one of the above function, getRegion(offsets, index) will set 'offsets' to point to an array of 'index offsets' for the cell referred by 'index'. A zero offset value (0) is always first in the list and refers to self. In the example above:
You obtain the cell-indices of the neighboring cells by adding offsets[n] to 'index': Example:
Derive GridNumeric specialized for numerical values
add Grid<> copy constructor and copy assignment
Public Types | |
| typedef CELL | cell_type |
| The type of cells (=CELL) | |
| typedef INDEX | index_type |
| the type for indices (=INDEX) | |
Public Member Functions | |
| Grid () | |
| constructor | |
| void | destroy () |
| Free memory. | |
| virtual | ~Grid () |
| Destructor. | |
| bool | periodic () |
| true if boundary conditions are periodic | |
| void | periodic (const bool p) |
| change boundary conditions | |
| void | setDimensions (const real infs[ORD], real sups[ORD], const int nbcells[ORD]) |
| set the sizes of the real space dimensions | |
| bool | hasDimensions () |
| true if setDimensions() was called | |
| INDEX | nbCells () const |
| total number of cells in the map | |
| INDEX | dim () const |
| INDEX | nbCells (int d) const |
| number of cells in dimensionality d | |
| INDEX | dim (int d) const |
| const real * | inf () const |
| position of the inferior (left/bottom/etc) edge | |
| real | inf (int d) const |
| const real * | sup () const |
| position of the superior (right/top/etc) edge | |
| real | sup (int d) const |
| const real * | delta () const |
| the widths of a cell | |
| real | delta (int d) const |
| const real * | cellWidth () const |
| real | cellWidth (int d) const |
| real | position (int d, real c) const |
| real | cellVolume () const |
| the volume of a cell | |
| real | diagonalLength () const |
| the length of the diagonal of a cell = sqrt( sum(cWidth[d]^2) ) | |
| real | minimumWidth (unsigned int min_size) const |
| the smallest cell width, along dimensions that have more than min_size cells | |
| bool | inside (const int coord[ORD]) const |
| checks if coordinates are inside the box | |
| bool | inside (const real w[ORD]) const |
| checks if point is inside the box | |
| void | bringInside (int coord[ORD]) const |
| periodic image | |
| void | setCoordinatesFromIndex (int coord[ORD], INDEX indx) const |
| conversion from index to coordinates | |
| void | setCoordinatesFromPosition (int coord[ORD], const real w[ORD], const real offset=0) const |
| conversion from Position to coordinates (offset should be in [0,1]) | |
| void | setPositionFromIndex (real w[ORD], INDEX indx, real offset=0) const |
| conversion from Index to Position (offset should be in [0,1]) | |
| void | setPositionFromCoordinates (real w[ORD], const int coord[ORD], real offset=0) const |
| conversion from Coordinates to Position (offset should be in [0,1]) | |
| INDEX | indexFromCoordinates (const int coord[ORD]) const |
| conversion from coordinates to index | |
| INDEX | index (const real w[ORD], const real offset=0) const |
| returns the index of the cell whose center is closest to the point w[] | |
| void | createCells () |
| allocate the array of cells | |
| bool | hasCells () const |
| returns true if cells have been allocated | |
| void | deleteCells () |
| deallocate array of cells | |
| void | clear () |
| call function clear() for all cells | |
| CELL * | cell_addr () |
| address of the cell array ( equivalent to &cell(0) ) | |
| CELL & | cell (const INDEX indx) const |
| return cell at index 'indx' | |
| CELL & | cell (const real w[ORD]) const |
| reference to CELL whose center is closest to w[] | |
| CELL & | cell (const int c[ORD]) const |
| reference to CELL of coordinates c[] | |
| CELL & | operator[] (const INDEX indx) const |
| operator access to a cell by index | |
| CELL & | operator() (const real w[ORD]) const |
| operator access to a cell by position | |
| CELL & | operator() (const int c[ORD]) const |
| short-hand access to a cell by co-oordinates | |
| void | create1D (real min, real max, int nbcells) |
| create a 1D-map | |
| CELL & | cell1D (const int x) const |
| access to cell for ORD==1 | |
| CELL & | cell2D (const int x, const int y) const |
| access to cell for ORD==2 | |
| CELL & | cell3D (const int x, const int y, const int z) const |
| access to cell for ORD==3 | |
| void | createSquareRegions (const real radius) |
| create regions which contains cells at a distance 'range' or less More... | |
| void | createRoundRegions (const real radius) |
| create regions which contains cells at a distance 'range' or less More... | |
| void | createSideRegions (const int radius) |
| regions that only contain cells of greater index. More... | |
| bool | hasRegions () const |
| true is createRegions() or createRoundRegions() was called | |
| int | getRegion (int *&offsets, const INDEX indx) const |
| set region array 'offsets' for cell index More... | |
| void | deleteRegions () |
| free memory occupied by the regions | |
| CELL | interpolate (const real w[ORD]) const |
| return linear interpolation of values stored at the center of each cell | |
| CELL | interpolate2D (const real w[ORD]) const |
| return linear interpolation of values stored at the center of each cell, but only if ORD==2 | |
| CELL | interpolate3D (const real w[ORD]) const |
| return linear interpolation of values stored at the center of each cell, but only if ORD==3 | |
| void | setValues (const CELL val) |
| set all cells to zero, if CELL supports this operation | |
| void | scaleValues (const CELL val) |
| set all cells to zero, if CELL supports this operation | |
| CELL | sumValues () const |
| sum of all values, if CELL supports the addition | |
| CELL | maxValue () const |
| maximum value over all cells | |
| CELL | minValue () const |
| minimum value over all cells | |
| bool | hasNegativeValue () const |
| true if any( cells[] < 0 ) | |
| CELL | sumValuesInRegion (const INDEX indx) const |
| the sum of the values in the region around cell referred by 'indx' | |
| CELL | avgValueInRegion (const INDEX indx) const |
| the sum of the values in the region around cell referred by 'indx' | |
| CELL | maxValueInRegion (const INDEX indx) const |
| the maximum of the values in the region around cell referred by 'indx' | |
| void | printValues (FILE *file, const real offset) const |
| write values to a file, with the position for each cell (file can be stdout) | |
| void | printValuesWithRange (FILE *file) const |
| write values to a file, with the range for each cell (file can be stdout) | |
Static Public Member Functions | |
| static int | ffloor (real x) |
| a fast floor function | |
Protected Attributes | |
| CELL * | gCell |
| The array of pointers to cells. | |
| INDEX | nCells |
| The number of cells in the map; size of cells[]. | |
| INDEX | gDim [ORD] |
| The number of cells in each dimension of the real space. | |
| real | gInf [ORD] |
| The position of the inferior edge (min) in each dimension. | |
| real | gSup [ORD] |
| The position of the superior edge (max) in each dimension. | |
| real | cWidth [ORD] |
| cWidth[d] = ( gSup[d] - inf[d] ) / gDim[d] | |
| real | cDelta [ORD] |
| cDelta[d] = 1.0 / cWidth[d] | |
| real | cVolume |
| The volume occupied by one cell. | |
|
inline |
Note: the range is specified in real units. The region covers an area of space that is approximately circular.
|
inline |
This is suitable for pair-wise interaction of particles, since it can be used to go through the cells one by one such that at the end, all pairs of cells have been considered only once.
Note: the range is taken specified in units of cells: 1 = 1 cell
|
inline |
Note: the range is specified in real units. the region will cover an area of space that is approximately square.
|
inline |
A zero offset is always first in the list.
\par Example:
Note: you must call createRegions() first